//
//  RootViewController.m
//  QRCode
//
//  Created by My Mac on 2017/5/27.
//  Copyright © 2017年 MyMac. All rights reserved.
//

#import "RootViewController.h"
#import "MyCollectionViewCell.h"
#import "ScanningViewController.h"
#import "IdentifyViewController.h"
#import "GenerateViewController.h"

@interface RootViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
{
    __weak IBOutlet UICollectionView *myCollectionView;
    NSArray *dataArr;
}
@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"二维码 <QRCode>";
    
    [myCollectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"myItem"];
    dataArr = @[@"扫描二维码",@"识别二维码",@"生成二维码"];
}

#pragma mark - 多少组
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
#pragma mark - 每组多少个item
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return dataArr.count;
}
#pragma mark - 每个item的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myItem" forIndexPath:indexPath];
    cell.label.text = dataArr[indexPath.item];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ScanningViewController *scanningVC = [ScanningViewController new];
    IdentifyViewController *identifyVC = [IdentifyViewController new];
    GenerateViewController *generateVC = [GenerateViewController new];
    switch (indexPath.row) {
        case 0:
            scanningVC.navigationItem.title = dataArr[indexPath.row];
            [self.navigationController pushViewController:scanningVC animated:YES];
            break;
        case 1:
            identifyVC.navigationItem.title = dataArr[indexPath.row];
            [self.navigationController pushViewController:identifyVC animated:YES];
            break;
        case 2:
            generateVC.navigationItem.title = dataArr[indexPath.row];
            [self.navigationController pushViewController:generateVC animated:YES];
            break;
    }
}

@end
